#include "../header/common.h"
#define MAXOBJECTS 2
#define MAXPOINTS 20

int kistr(int *level,SDL_Surface *screen)
{
  SDL_Surface *windows,*easys,*mediums,*hards,*temp,*background;
  SDL_Surface *easyspr,*mediumspr,*hardspr;
  SDL_Rect easy,medium,hard;
  SDL_Event event;
  int x,y;
  Uint8 SDL_GetRelativeMouseState(int *x, int *y);

  switch(screen->w)
    {
    case 640:
      background = SDL_LoadBMP("image/640480/menubackground.bmp");
      windows = SDL_LoadBMP("image/640480/ki.bmp");
      easys = SDL_LoadBMP("image/640480/buttons/leicht.bmp");
      mediums = SDL_LoadBMP("image/640480/buttons/medium.bmp");
      hards = SDL_LoadBMP("image/640480/buttons/hard.bmp");
      easyspr = SDL_LoadBMP("image/640480/buttonspressed/leicht1.bmp");
      mediumspr = SDL_LoadBMP("image/640480/buttonspressed/medium1.bmp");
      hardspr = SDL_LoadBMP("image/640480/buttonspressed/hard1.bmp");
      temp=SDL_LoadBMP("image/640480/temp.bmp");
      break;
    case 800:
      background = SDL_LoadBMP("image/800600/menubackground.bmp");
      windows = SDL_LoadBMP("image/800600/ki.bmp");
      easys = SDL_LoadBMP("image/800600/buttons/leicht.bmp");
      mediums = SDL_LoadBMP("image/800600/buttons/medium.bmp");
      hards = SDL_LoadBMP("image/800600/buttons/hard.bmp");
      easyspr = SDL_LoadBMP("image/800600/buttonspressed/leicht1.bmp");
      mediumspr = SDL_LoadBMP("image/800600/buttonspressed/medium1.bmp");
      hardspr = SDL_LoadBMP("image/800600/buttonspressed/hard1.bmp");
      temp=SDL_LoadBMP("image/800600/temp.bmp");
      break;
    case 1024:
      background = SDL_LoadBMP("image/1024768/menubackground.bmp");
      windows = SDL_LoadBMP("image/1024768/ki.bmp");
      easys = SDL_LoadBMP("image/1024768/buttons/leicht.bmp");
      mediums = SDL_LoadBMP("image/1024768/buttons/medium.bmp");
      hards = SDL_LoadBMP("image/1024768/buttons/hard.bmp");
      easyspr = SDL_LoadBMP("image/1024768/buttonspressed/leicht1.bmp");
      mediumspr = SDL_LoadBMP("image/1024768/buttonspressed/medium1.bmp");
      hardspr = SDL_LoadBMP("image/1024768/buttonspressed/hard1.bmp");
      temp=SDL_LoadBMP("image/1024768/temp.bmp");
      break;
    }
  SDL_SetColorKey(windows, SDL_SRCCOLORKEY, SDL_MapRGB(windows->format, 0, 0, 255)); 
  SDL_SetColorKey(easys, SDL_SRCCOLORKEY, SDL_MapRGB(easys->format, 0, 0, 255)); 
  SDL_SetColorKey(mediums, SDL_SRCCOLORKEY, SDL_MapRGB(mediums->format, 0, 0, 255)); 
  SDL_SetColorKey(hards, SDL_SRCCOLORKEY, SDL_MapRGB(hards->format, 0, 0, 255)); 
  SDL_SetColorKey(easyspr, SDL_SRCCOLORKEY, SDL_MapRGB(easyspr->format, 0, 0, 255)); 
  SDL_SetColorKey(mediumspr, SDL_SRCCOLORKEY, SDL_MapRGB(mediumspr->format, 0, 0, 255)); 
  SDL_SetColorKey(hardspr, SDL_SRCCOLORKEY, SDL_MapRGB(hardspr->format, 0, 0, 255)); 

  easy.y=medium.y=hard.y=((screen->h/3)*2);
  easy.x=screen->w/5;
  medium.x=(easy.x+easys->w+30);
  hard.x=(medium.x+mediums->w+30);
  
  SDL_BlitSurface(background,NULL,screen,NULL);
  SDL_Flip(screen);
  SDL_SetAlpha(temp, SDL_SRCALPHA | SDL_RLEACCEL, 200);
  SDL_BlitSurface(temp,NULL,screen,NULL); 
  SDL_BlitSurface(easys,NULL,windows,&easy);
  SDL_BlitSurface(mediums,NULL,windows,&medium);
  SDL_BlitSurface(hards,NULL,windows,&hard);
  SDL_BlitSurface(windows,NULL,screen,NULL);
  SDL_Flip(screen);

  while (*level>2) 
    {
      while (SDL_PollEvent(&event)) 
	{
	  SDL_PumpEvents();
	  if(SDL_GetMouseState(&x, &y) &SDL_BUTTON(1)) 
	    {
	      if((y>easy.y)&&(y<(easy.y+easys->h)))
		{
		  if((x>easy.x)&&(x<easy.x+easys->w))*level=0;
		  if((x>medium.x)&&(x<medium.x+mediums->w))*level=1;
		  if((x>hard.x)&&(x<hard.x+hards->w))*level=2;
		}
	    }
	  if(*level>2)
	    {
	      if(click_button(easy,x,y))
		{
		  SDL_BlitSurface(easyspr, NULL, screen, &easy);
		  SDL_Flip(screen);
		}else SDL_BlitSurface(easys,NULL,screen, &easy);
	      if(click_button(medium,x,y))
		{
		  SDL_BlitSurface(mediumspr, NULL, screen, &medium);
		  SDL_Flip(screen);
		}else SDL_BlitSurface(mediums,NULL,screen, &medium);
	      if(click_button(hard,x,y))
		{
		  SDL_BlitSurface(hardspr, NULL, screen, &hard);
		  SDL_Flip(screen);
		}else SDL_BlitSurface(hards,NULL,screen, &hard);
	    }	  
	  switch (event.type) 
	    {
	    case SDL_QUIT:
	      return 1;
	      break;
	    }
	}
      SDL_Delay(20);
    }
  SDL_FreeSurface(easys);
  SDL_FreeSurface(easyspr);
  SDL_FreeSurface(mediums);
  SDL_FreeSurface(mediumspr);
  SDL_FreeSurface(hards);
  SDL_FreeSurface(hardspr);
  SDL_FreeSurface(windows);
  SDL_FreeSurface(temp);
  return 0;
}

int singleplayer(SDL_Surface *screen,int mode,char playername[])
{
  SDL_Surface *balls, *barrs, *barls, *background, *boxs,*temp;
  SDL_Rect obj[MAXOBJECTS],ball[2],field,box[1];
  SDL_Event event;
  int done=0,ballnumber,pointr=0,pointl=0,wait=0,sound,tmp,activebox=0,activeboxtmp=1,steptmp;
  int xway[2],yway[2],frames=0,step,level=10,autoaim=0,goboxtime=10,killeractive=0,maxballs=1;
  int infoplace,infozeile=2,font3high,autoaimtmp,go,xwaytmp=0,kill=0,ywaytmp=0,barspeed,points,brake=15;
  long unsigned int boxtime=time(NULL),pointtime;
  TTF_Font *font, *font2, *font3;
  char string[10],stringlong[35],pointstring[20];
  Mix_Chunk *soundeffect;
  Uint32 timer=SDL_GetTicks(),frameswait,seconds=SDL_GetTicks();
  soundeffect = Mix_LoadWAV("sound/bar.wav");
  TTF_Init();

  /*Mode 1=Singleplayer
    Mode 2=Multiplayer
    Mode 3=Online
    Level 0=Easy
    Level 1=Medium
    Level 2=Hard
  */
  srand (time(NULL));

  /*Balkenpositionen werden festgelegt*/
  obj[0].x=50;obj[0].y=150;
  obj[1].x=((screen->w)-(screen->w/10));obj[1].y=150;
  field.x=(screen->w)/33;field.w=(screen->w)-(field.x*2);
  field.y=(screen->h)/5-((screen->w)/100);field.h=(screen->h)-((screen->h)/4)-((screen->w)/25);
  switch((screen->w))
    {
    case 640 :
      font = TTF_OpenFont("spranq_eco_sans_regular.ttf", 56);
      font2 = TTF_OpenFont("spranq_eco_sans_regular.ttf", 22);
      font3 = TTF_OpenFont("arial.ttf", 10);
      balls = SDL_LoadBMP("image/640480/ball.bmp");
      barrs = SDL_LoadBMP("image/640480/barr.bmp");
      barls = SDL_LoadBMP("image/640480/barl.bmp");
      temp=SDL_LoadBMP("image/640480/temp.bmp");
      background = SDL_LoadBMP("image/640480/background.bmp");
      boxs = SDL_LoadBMP("image/640480/box.bmp");
      step=5;
      font3high=15;
      barspeed=15;
      break;

    case 800 :
      font = TTF_OpenFont("spranq_eco_sans_regular.ttf", 70);
      font2= TTF_OpenFont("spranq_eco_sans_regular.ttf", 27); 
      font3 = TTF_OpenFont("arial.ttf", 13);          
      balls = SDL_LoadBMP("image/800600/ball.bmp");
      barrs = SDL_LoadBMP("image/800600/barr.bmp");
      barls = SDL_LoadBMP("image/800600/barl.bmp");
      temp=SDL_LoadBMP("image/800600/temp.bmp");
      background = SDL_LoadBMP("image/800600/background.bmp");
      boxs = SDL_LoadBMP("image/800600/box.bmp");
      step=7;
      font3high=20;
      barspeed=23;
      break;

    case 1024 :
      font = TTF_OpenFont("spranq_eco_sans_regular.ttf", 90);
      font2 = TTF_OpenFont("spranq_eco_sans_regular.ttf", 35);
      font3 = TTF_OpenFont("arial.ttf", 16);     
      balls = SDL_LoadBMP("image/1024768/ball.bmp");
      barrs = SDL_LoadBMP("image/1024768/barr.bmp");
      barls = SDL_LoadBMP("image/1024768/barl.bmp");
      background = SDL_LoadBMP("image/1024768/background.bmp");
      temp=SDL_LoadBMP("image/1024768/temp.bmp");
      boxs = SDL_LoadBMP("image/1024768/box.bmp");
      step=9;
      font3high=30;
      barspeed=30;
      break;
    }

    
  SDL_SetAlpha(temp, SDL_SRCALPHA | SDL_RLEACCEL, 200);
  if(mode==1){if(kistr(&level,screen)==1)return 1;};

  SDL_BlitSurface(background,NULL,screen,NULL);
  SDL_FillRect(screen,&field,SDL_MapRGB(screen->format,255,255,255));  

  steptmp=step;

  /*Box wird initialisiert*/
  box[0].w=boxs->w;box[0].h=boxs->h;
  box[0].x=(obj[0].x+(barls->w));
  box[0].y=((int)(field.y+field.h-box[0].h)*(rand()/(RAND_MAX+1.0)));
  if(box[0].y<field.y)box[0].y+=field.y;

  if(mode==1)
    { 
      drawText(screen,screen,font2,playername,((screen->w)/12),(screen->h/15)*14,0,0,0);
      switch(level)
	{
	case 0 : drawText(screen,screen,font2,"KI=>easy",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
	  break;
	case 1 : drawText(screen,screen,font2,"KI=>medium",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
	  break;      
	case 2 : drawText(screen,screen,font2,"KI=>hard",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
	  break;
	}
    }
  if(mode==2)
    {	
      drawText(screen,screen,font2,"Player 1",((screen->w)/11),(screen->h/15)*14,0,0,0);
      drawText(screen,screen,font2,"Player 2",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);  
    }

  for(ballnumber=0;ballnumber<2;ballnumber++)
    {
      /*Ballgeschwindigkeiten werden geladen*/
      xway[ballnumber]=1+(2*-ballnumber);yway[ballnumber]=1+(2*-ballnumber);
      /*Ballgroesse wird uebergeben*/
      ball[ballnumber].w = balls->w;
      ball[ballnumber].h = balls->h;
      /*Ballstartpositionen werden vergeben*/
      ball[ballnumber].x=(((screen->w)/2)+(balls->w*ballnumber*3));
      ball[ballnumber].y=(((screen->h)/2)-(balls->h*ballnumber*3));
    }

  /*Balken werden gezeichnet*/
  SDL_BlitSurface(barrs,NULL,screen,&obj[1]);
  SDL_BlitSurface(barls,NULL,screen,&obj[0]);

  infoplace=((screen->w/10));infozeile=0;
  drawText(screen,background,font3,"-------Info-------",infoplace,(infozeile*font3high+2),255,255,255);
  
  options(1,&sound,&tmp);
  if(sound){play(0);play(1);} 

  drawText(screen,background,font,"0",(screen->w/100)*33 ,(screen->h/36),255,255,255);
  drawText(screen,background,font,"0",(screen->w/100)*57,(screen->h/36),255,255,255);
  string[0]=0; 

  drawText(screen,background,font,"Ready!",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);
  SDL_Flip(screen);
  SDL_Delay(1000);
  drawText(screen,background,font,"Steady!",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);
  SDL_Flip(screen);
  SDL_Delay(1000);
  drawText(screen,background,font,"GO!!!      ",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);
  SDL_Flip(screen);
  SDL_Delay(500);
  drawText(screen,background,font,"                ",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);

  pointtime=time(NULL);
 
/*Programm Exit wird festgelegt*/    
  while (!done) 
    {
      while (SDL_PollEvent(&event)) 
	{
	  switch(event.type) 
	    {
	    case SDL_QUIT:
	      SDL_FreeSurface(background);
	      SDL_FreeSurface(temp);
	      SDL_FreeSurface(balls);
	      SDL_FreeSurface(barls);
	      SDL_FreeSurface(barrs); 
	      SDL_FreeSurface(boxs);
	      return 1;
	      break;
	    }
	}
      /*Balken werde geloescht*/
      SDL_FillRect(screen,&obj[0],SDL_MapRGB(screen->format,255,255,255));
      SDL_FillRect(screen,&obj[1],SDL_MapRGB(screen->format,255,255,255));

      /*Tastatur wird gecheckt*/
      autoaimtmp=autoaim;
      keyhandler(obj,screen,&done,&mode,&autoaim,&barspeed);
      if(autoaim!=autoaimtmp)
	{
	  infozeile=3;
	  switch(autoaim)
	    {
	    case 0: drawText(screen,background,font3,"Autoaim:OFF",infoplace,(infozeile*font3high+2),255,255,255);
	      break;
	    case 1: drawText(screen,background,font3,"Autoaim:ON  ",infoplace,(infozeile*font3high+2),255,255,255);
	      break;
	    }
	}
      /*KI wird beim Singleplayer initialisiert*/
      if((mode==1)||(autoaim==1))ki(ball,obj,screen,&level,&autoaim,&mode);

      /*Balken werden geblittet*/
      SDL_BlitSurface(barrs,NULL,screen,&obj[1]);	   
      SDL_BlitSurface(barls,NULL,screen,&obj[0]);	   

      /*Ballberechnung wird initialisiert*/
      for(ballnumber=0;ballnumber<maxballs;ballnumber++)
	{
	  SDL_FillRect(screen,&ball[ballnumber],SDL_MapRGB(screen->format,255,255,255));
	  xwaytmp=xway[0];
	  ywaytmp=yway[0];
 	  checkcollision(ball[ballnumber],screen,xway,yway,&ballnumber,&step);
	  if(killeractive!=0)
	    {
	      switch(killeractive)
		{
		case 1 :
		  if((xwaytmp<0)&&(xway[0]>0))step=steptmp*3;
		  if((xwaytmp>0)&&(xway[0]<0))step=steptmp;
		  break;
		case 2 :
		  if((xwaytmp>0)&&(xway[0]<0))step=steptmp*3;
		  if((xwaytmp<0)&&(xway[0]>0))step=steptmp;
		  break;
		}
	    }
	  else step=steptmp;
	  if((xwaytmp!=xway[0])||(ywaytmp!=yway[0]))kill++;
	  ball[ballnumber].x+=xway[ballnumber]*step;
	  ball[ballnumber].y+=yway[ballnumber]*step;
	  if(ball[ballnumber].x<(obj[0].x-10))
	    {
	      burn(ball[ballnumber],screen);
	      brake+=2;
	      pointr++;
	      snprintf(string,sizeof(string),"%d",pointr);
	      drawText(screen,background,font,string,(screen->w/100)*57,(screen->h/36),255,255,255);	      
	      wait=1;
	    }
	  if(ball[ballnumber].x>(obj[1].x+10))
	    {
	      burn(ball[ballnumber],screen);
	      brake+=2;
	      pointl++;	       
	      snprintf(string,sizeof(string),"%d",pointl);
	      drawText(screen,background,font,string,(screen->w/100)*33,(screen->h/36),255,255,255);
	      wait=1;
	    }	  
 	  if((pointl>MAXPOINTS)||(pointr>MAXPOINTS)){done=1;wait=0;} 
	  if(wait!=1)SDL_BlitSurface(balls,NULL,screen,&ball[ballnumber]);
	  SDL_Flip(screen);
	}
 
     if((xway[0]!=xwaytmp)&&(sound))Mix_PlayChannel(-1, soundeffect, 0);

      /*Bilder pro Sekunde werden berechnet und ausgegeben*/
     if((SDL_GetTicks()-seconds)>=1000)
	{
	  seconds=SDL_GetTicks();
	  snprintf(string,sizeof(string),"%d FPS",frames);infozeile=1;
	  drawText(screen,background,font3,string,infoplace,(infozeile*font3high+2),255,255,255);
	  if(frames<58)brake--;if(frames>62)brake++;
  	  frames=0;  

	  if(kill>(screen->w/100))
	    {
 	      wait=1;
	      SDL_FillRect(screen,&ball[0],SDL_MapRGB(screen->format,255,255,255));
	      SDL_FillRect(screen,&ball[1],SDL_MapRGB(screen->format,255,255,255));
	      SDL_BlitSurface(background,NULL,screen,NULL);
	      SDL_BlitSurface(barrs,NULL,screen,&obj[1]);
	      SDL_BlitSurface(barls,NULL,screen,&obj[0]);
	      snprintf(string,sizeof(string),"%d",pointl);
	      drawText(screen,background,font,string,(screen->w/100)*33,(screen->h/36),255,255,255);
	      snprintf(string,sizeof(string),"%d",pointr);
	      drawText(screen,background,font,string,(screen->w/100)*57,(screen->h/36),255,255,255);
	      infoplace=((screen->w/10));infozeile=0;
	      drawText(screen,background,font3,"-------Info-------",infoplace,(infozeile*font3high+2),255,255,255);
	      if(mode==1)
		{ 
		  drawText(screen,screen,font2,playername,((screen->w)/12),(screen->h/15)*14,0,0,0);
		  switch(level)
		    {
		    case 0 : drawText(screen,screen,font2,"KI=>easy",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
		      break;
		    case 1 : drawText(screen,screen,font2,"KI=>medium",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
		      break;      
		    case 2 : drawText(screen,screen,font2,"KI=>hard",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);
		      break;
		    }
		}
	      if(mode==2)
		{	
		  drawText(screen,screen,font2,"Player 1",((screen->w)/11),(screen->h/15)*14,0,0,0);
		  drawText(screen,screen,font2,"Player 2",((screen->w)/15)*11,(screen->h/15)*14,0,0,0);  
		}
	      SDL_Flip(screen);
	    }
	   kill=0;
	}   

      /*Das Spiel wartet ca. 15ms um ca. 60FPS zu erreichen*/
     SDL_Delay(brake);

      /*Berechnung der "Special-Boxes"*/
      if((time(NULL)-boxtime)>goboxtime)
	{
	  goboxtime=(int)20*(rand()/(RAND_MAX+1.0));
	  if(goboxtime<10)goboxtime+=10;infozeile=2;
	  snprintf(stringlong,sizeof(stringlong),"Next box in %d s  ",goboxtime);
	  drawText(screen,background,font3,stringlong,infoplace,(infozeile*font3high+2),255,255,255);
	  boxtime=time(NULL);
	  activebox=activeboxtmp;
	  special(0,obj,barls,barrs,screen,&killeractive,&barspeed,&maxballs);
	}
      if(activebox!=0)
	{
	  activeboxtmp=activebox;
	  randombox(screen,box,&activebox,obj,barls,barrs,boxs,field,&killeractive,&barspeed,&maxballs);
	}
      if((activebox!=activeboxtmp)&&(activebox!=0))
	{
	  activeboxtmp=activebox;
	  activebox=0;
	}
      
      
      /*Die Bildschirm-Surface wird "gewendet"*/
      SDL_Flip(screen);

      if(wait==1)
	{
	  brake++;
	  for(ballnumber=0;ballnumber<maxballs;ballnumber++)
	    {
	      SDL_FillRect(screen,&ball[ballnumber],SDL_MapRGB(screen->format,255,255,255));
	      ball[ballnumber].x=(((screen->w)/2)+((ballnumber*3)*(balls->w)));
	      ball[ballnumber].y=(((screen->h)/2)+((ballnumber*3)*(balls->h)));
	      if(((int)100*(rand()/(RAND_MAX+1.0)))<50)xway[ballnumber]=-1;else xway[ballnumber]=1;
	      if(((int)100*(rand()/(RAND_MAX+1.0)))<50)yway[ballnumber]=-1;else yway[ballnumber]=1;
	    }
	  drawText(screen,background,font,"GO!!!",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);
	  SDL_Flip(screen);
	  SDL_Delay(300);
	  drawText(screen,background,font,"          ",((screen->w/2)-(screen->w/10)),((screen->h/2)-(screen->w/10)),255,0,0);
	  step=steptmp;
	  wait=0;
	  maxballs=1;
	}
      /*Frames werden hochgezaehlt*/
      frames++;
    }

  /*Die Surfaces werden wieder geloescht*/
  SDL_FreeSurface(balls);
  SDL_FreeSurface(barls);
  SDL_FreeSurface(barrs); 
  SDL_FreeSurface(boxs);
  
  /*Darstellung des Gewinners*/
  if((pointl>MAXPOINTS)||(pointr>MAXPOINTS))
    {
      /*Berechnung der Punkte*/
      if(mode==1)
	{
	  points=((600-(time(NULL)-pointtime)-pointr)*(level+1));
	  snprintf(pointstring,sizeof(pointstring),"with %d points!!!",points);
	}
      drawText(screen,background,font,"And the winner is...",80,((screen->h/2)-((screen->w/10)*2)),255,0,0);
      SDL_Flip(screen);
      SDL_Delay(1000);
      if(pointl<pointr)
	{
	  if(mode==1)
	    {
	      drawText(screen,background,font,"Mr. Computer!",80,((screen->h/2)-(screen->w/10)),255,0,0);
	      if(sound)play(3);
	    }
	  if(mode==2)drawText(screen,background,font,"Player 2!",80,((screen->h/2)-(screen->w/10)),255,0,0);
	}
      else
	{
	  if(mode==1)
	    {
	      play(4);
	      drawText(screen,background,font,playername,screen->w/3,((screen->h/2)-(screen->w/10)),255,0,0);
	      drawText(screen,background,font,pointstring,screen->w/6,((screen->h/3)*2),255,0,0);
	    }
	  if(mode==2)drawText(screen,background,font,"Player 1!",80,((screen->h/2)-(screen->w/10)),255,0,0);
	}
      SDL_Flip(screen);
      SDL_Delay(2000);
      if((mode==1)&&(pointl>MAXPOINTS)&&(highscore(1,screen,playername,points)==2))
	{
	  for(step=0;step<6;step++)
	    {
	      drawText(screen,background,font,"NEW HIGHSCORE!!!",screen->w/10,screen->h/2-10,255,0,0);
	      SDL_Flip(screen);
	      SDL_Delay(300);
	      SDL_BlitSurface(temp,NULL,screen,NULL);
	      SDL_Flip(screen);
	      SDL_Delay(300);
	    }
	}
    }
  SDL_FreeSurface(background);
  SDL_FreeSurface(temp);
  return 0;
}

